<template>
    <div class="page">
        <div class="header">
            <div class="welcome">
                <h1>欢迎使用智面宝典</h1>
                <p>您的智能面试助手</p>
            </div>
            <div class="user-info" @click="handleUserClick">
                <img :src="userStore?.userInfo?.avatar || '/src/assets/images/mine/defaultAvatar.png'" class="avatar">
            </div>
        </div>

        <div class="content">
            <div class="feature-cards">
                <div class="card" @click="navigateTo('/interview')">
                    <div class="card-icon">
                        <img src="@/assets/images/home/interview.png" alt="面试">
                    </div>
                    <div class="card-text">
                        <h3>智能面试</h3>
                        <p>模拟真实面试场景</p>
                    </div>
                </div>

                <div class="card" @click="navigateTo('/practice')">
                    <div class="card-icon">
                        <img src="@/assets/images/home/practice.png" alt="练习">
                    </div>
                    <div class="card-text">
                        <h3>面试练习</h3>
                        <p>AI针对性练习提升</p>
                    </div>
                </div>

                <div class="card" @click="navigateTo('/resources')">
                    <div class="card-icon">
                        <img src="@/assets/images/home/resources.png" alt="资源">
                    </div>
                    <div class="card-text">
                        <h3>面试资源</h3>
                        <p>丰富的面试资料</p>
                    </div>
                </div>

                <div class="card" @click="navigateTo('/analysis')">
                    <div class="card-icon">
                        <img src="@/assets/images/home/analysis.png" alt="分析">
                    </div>
                    <div class="card-text">
                        <h3>面试分析</h3>
                        <p>专业面试评估</p>
                    </div>
                </div>
            </div>

            <div class="recent-section">
                <h2>最近面试</h2>
                <div class="recent-list">
                    <div v-if="recentInterviews.length === 0" class="empty-state">
                        <p>暂无面试记录</p>
                        <!-- <button @click="navigateTo('/interview')">开始面试</button> -->
                    </div>
                    <div v-else v-for="(interview, index) in recentInterviews" :key="index" class="recent-item">
                        <div class="interview-info">
                            <h3>{{ interview.title }}</h3>
                            <p>{{ interview.date }}</p>
                        </div>
                        <div class="interview-score">
                            <span>{{ interview.score }}分</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <TabNav />
    </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import TabNav from '@/components/TabNav/TabNav.vue'
import { ref } from 'vue'

defineOptions({
    name: 'HomePage'
})

const router = useRouter()
const userStore = useUserStore()

// 处理用户头像点击
const handleUserClick = () => {
    router.push('/mine')
}

// 导航函数
const navigateTo = (path) => {
    router.push(path)
}

// 模拟最近面试数据
const recentInterviews = ref([])

</script>

<style lang="scss" scoped>
.page {
    background: linear-gradient(135deg, #e6f3ff 0%, #b6d9ff 100%);
    width: 100%;
    height: 100vh;
    position: relative;

    .header {
        padding: 15px 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .welcome {
            color: #333;

            h1 {
                font-size: 24px;
                margin-bottom: 4px;
                font-weight: 600;
                text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            }

            p {
                font-size: 14px;
                color: #666;
            }
        }

        .user-info {
            .avatar {
                width: 40px;
                height: 40px;
                border-radius: 50%;
                border: 2px solid #fff;
                object-fit: cover;
                box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            }
        }
    }

    .content {
        position: absolute;
        top: 100px;
        width: 100%;
        min-height: calc(100vh - 100px);
        background-color: #fff;
        border-radius: 25px 25px 0 0;
        padding: 20px;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);

        .feature-cards {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 12px;
            padding: 8px;
            margin-bottom: 20px;

            .card {
                background: rgba(255, 255, 255, 0.9);
                padding: 12px;
                border-radius: 16px;
                cursor: pointer;
                transition: all 0.3s ease;
                border: 1px solid rgba(74, 144, 226, 0.1);
                box-shadow: 0 4px 12px rgba(74, 144, 226, 0.05);
                display: flex;
                flex-direction: column;
                align-items: center;
                text-align: center;

                &:hover {
                    transform: translateY(-2px);
                    box-shadow: 0 8px 16px rgba(74, 144, 226, 0.1);
                }

                .card-icon {
                    margin-bottom: 12px;
                    width: 32px;
                    height: 32px;
                    display: flex;
                    align-items: center;
                    justify-content: center;

                    img {
                        width: 100%;
                        height: 100%;
                        object-fit: contain;
                    }
                }

                .card-text {
                    h3 {
                        font-size: 15px;
                        color: #333;
                        margin-bottom: 4px;
                        font-weight: 500;
                    }

                    p {
                        font-size: 12px;
                        color: #666;
                        margin: 0;
                    }
                }
            }
        }

        .recent-section {
            h2 {
                font-size: 18px;
                color: #333;
                margin-bottom: 15px;
                font-weight: 600;
            }

            .empty-state {
                text-align: center;
                padding: 30px 20px;
                background: rgba(74, 144, 226, 0.05);
                border-radius: 16px;
                border: 1px dashed rgba(74, 144, 226, 0.2);

                p {
                    color: #666;
                    margin-bottom: 20px;
                    font-size: 15px;
                }

                button {
                    padding: 12px 32px;
                    background: #4a90e2;
                    color: white;
                    border: none;
                    border-radius: 12px;
                    font-size: 15px;
                    font-weight: 500;
                    cursor: pointer;
                    transition: all 0.3s ease;
                    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.2);

                    &:hover {
                        background: #357abd;
                        transform: translateY(-1px);
                    }

                    &:active {
                        transform: translateY(0);
                    }
                }
            }
        }
    }
}
</style>